﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public partial class DayToDayManagement_CMDUP : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("300100101");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            ((Button)BUTTONDJLIST1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJLIST1.Controls[6]).Enabled = false;
            uptype();
            Bind();
        }
    }

    private void uptype()
    {
        List<Model.UPTYPE> properties = new BLL.UPTYPE().GetAllList();
        DropDownList1.DataSource = properties;
        DropDownList1.DataTextField = "UT_NAME";
        DropDownList1.DataValueField = "UT_CODE";
        DropDownList1.DataBind();
        ListItem li = new ListItem();
        li.Text = " ";
        li.Value = "-1";
        DropDownList1.Items.Insert(0, li);
    }
    private void Bind()
    {
        string sqlstr = "";
        sqlstr += TextBox1.Text.Trim() == "" ? "" : " and cu_id='" + TextBox1.Text.Trim() + "' ";
        sqlstr += DropDownList1.SelectedValue.Trim() == "-1" ? "" : " and cu_uptype='" + DropDownList1.SelectedValue + "' ";
        sqlstr += dropCheck.SelectedValue == "-1" ? "" : " and cu_check=" + dropCheck.SelectedValue + " ";
        sqlstr += TextBox2.Text.Trim() == "" ? "" : " and cu_update>='" + TextBox2.Text.Trim() + "' " ;
        sqlstr += TextBox3.Text.Trim() == "" ? "" : " and cu_update<='" + TextBox3.Text.Trim() + "'";
        
        int pageCount, rowCount;
        List<Model.CMDUP> properties = new BLL.CMDUP().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "CU_UPDATE", true, sqlstr, out pageCount, out rowCount);
        CMDUPListControl1.Bind(properties);
        AspNetPager1.RecordCount = rowCount;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }

    public void Add()
    {
        if (Check.CheckPermission("300100101", "00001"))
        {
            Response.Redirect("CMDUPEDIT.aspx");
        }
        else
        {
            Share.Alert(this.Page,"无权操作"); return;
        }
    }
    public void Update()
    {
        if (Check.CheckPermission("300100101", "00002"))
        {
            List<string> s = CMDUPListControl1.Selected;
            if (s.Count > 0)
            {
                Response.Redirect("CMDUPEDIT.aspx?code=" + s[0]);
            }
            else
            {
                Share.Alert(this.Page, "请选择一条需要编辑的记录"); return;
            }
        }
        else
        {
            Share.Alert(this.Page,"无权操作"); return;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
        Bind();
    }
}
